<!DOCTYPE html>
<html>
<head>
    <title>GeoMesa Leaflet Map Viewer</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
          integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
          crossorigin=""/>
    <script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
            integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
            crossorigin=""></script>
    <script src="https://cdn.rawgit.com/Leaflet/Leaflet.heat/v0.2.0/dist/leaflet-heat.js"></script>
    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #mapid {
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
<div id="mapid"></div>
<script>

    // Marker used to split file in order to inject data and generated code.
    |codegen|

    // Create a custom points marker since the default pin is expensive to render
    var geojsonMarkerOptions = {
        radius: 8,
        fillColor: "#ff7800",
        color: "#000",
        weight: 1,
        opacity: 1,
        fillOpacity: 0.8
    }

    // Load the data we wrote out in 'codegen' into a geojsonLayer
    var geojsonLayer = L.geoJSON(points, {
        pointToLayer: function (feature, latlng) {
            return L.circleMarker(latlng, geojsonMarkerOptions);
        },
        onEachFeature: onEachFeature
    });

    // Separate the points and heatmap into different layer groups so they can be
    // toggled on and off.
    var pointsLG = L.layerGroup([geojsonLayer]);
    var heatLG = L.layerGroup([heat]);

    // Base maps
    var greyscale = new L.TileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
        subdomains: 'abcd',
        maxZoom: 19
    });

    var osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    });

    // Create the map and set the default layers.
    var geomesaMap = L.map('mapid', {
        layers: [greyscale, pointsLG]
    });
    geomesaMap.fitBounds(geojsonLayer.getBounds());

    // Create the control groups for the layers
    var baseMaps = {
        "Greyscale": greyscale,
        "OSM": osm
    }

    var overlayMaps = {
        "Features": pointsLG,
        "Heatmap": heatLG
    }

    // Add controls to the map
    L.control.layers(baseMaps, overlayMaps).addTo(geomesaMap);
    L.control.scale().addTo(geomesaMap);

</script>

</body>
</html>
